<?php

namespace app\api\controller;

use hg\apidoc\annotation as Apidoc;
use hg\apidoc\annotation\Param;
use hg\apidoc\annotation\Query;
use hg\apidoc\annotation\Returned;
use hg\apidoc\annotation\Header;
use app\BaseController;
use think\facade\View;
use think\facade\Db;
use think\response\Json;
/**
 * 文案创作_会员
 *
 * api-CopywritingMember
 *
 * @Apidoc\Title("文案创作_会员")
 * @Apidoc\Group("api")
 */
class CopywritingMember extends Auth
{
    /**
     * add
     * @Apidoc\Title("保存会员文案创作")
     */
    public function add()
    {
        $data = input();
        $data['member_id'] = $this->request->uid;
        $data['name'] = Common::getPrompt($data['copywriting_id'],$data['form']);
        $copywritingMember = \app\common\model\CopywritingMember::create($data);
        return success('', [
            'id' => $copywritingMember->id
        ]);
    }

    /**
     * update
     *  @Apidoc\Title("更新会员文案创作")
     */
    public function update()
    {
        $id = input('id');
        $member_id = \app\common\model\CopywritingMember::where('id', $id)->value('member_id');
        if($member_id != $this->request->uid) {
            return error('非法请求！');
        }
        \app\common\model\CopywritingMember::update([
            'id' => $id,
            'result_content' => input('result_content')
        ]);
        return success();
    }

    /**
     * delete
     * @Apidoc\Title("删除会员文案创作")
     */
    public function delete()
    {
        $id = input('id',0, 'intval');
        $member_id = \app\common\model\CopywritingMember::where('id', $id)->value('member_id');
        if($member_id != $this->request->uid) {
            return error('非法请求！');
        }
        \app\common\model\CopywritingMember::destroy($id);
        return success();
    }

    /**
     * list
     * @Apidoc\Title("会员文案创作列表")
     */
    public function list(): Json
    {
        $data = \app\common\model\CopywritingMember::where('member_id', $this->request->uid)
            ->where('copywriting_id', input('copywriting_id'))
            ->order('id', 'desc')->select();
        return success('', $data);
    }
}
